<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <title>表格</title>
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/font-awesome-4.7.0/css/font-awesome.css" media="all"/>
</head>
<body class="layui-bg-gray">
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-card">
            <div class="layui-card-header"><b>修改用户</b></div>
            <div class="layui-card-body">
                <form class="layui-form layui-form-pane" >
                    <input type="hidden" name="id" required  lay-verify="required" id="id" autocomplete="off" class="layui-input">
                    <div class="layui-form-item"  pane>
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="username" name="username" id="username" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">身份</label>
                        <div class="layui-input-block">
                            <input type="nickname" name="nickname" id="nickname" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">性别</label>
                        <div class="layui-input-block">
                            <select name="sex" lay-verify="required">
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">电话 </label>
                        <div class="layui-input-block">
                            <input type="phone" name="phone" id="chaptercount" required  lay-verify="required" placeholder="请输入章节数目" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">邮件 </label>
                        <div class="layui-input-block">
                            <input type="email" name="email" id="processstate" required  lay-verify="required" placeholder="请输入连载状态" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">生日 </label>
                        <div class="layui-input-block">
                            <input type="birthday" name="birthday" id="state" required  lay-verify="required" placeholder="请输入书籍状态" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item" pane>
                        <label class="layui-form-label">状态 </label>
                        <div class="layui-input-block">
                            <select name="status" lay-verify="required">
                            </select> </div>
                    </div>
                    <div class="layui-form-item" >
                        <button id="edit" class="layui-btn" lay-submit lay-filter="formDemo" lay-event="edit">确定修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.all.js" charset="utf-8"></script>
</body>
<script>
    layui.use(['form','layer'], function(){
        var form = layui.form;
        var layer=layui.layer;
        var $=layui.jquery;
        var data = layui.sessionData("user/edit.html")["user-id"];
        console.log(data);
        $.get("/sysusers",{id:data.id},function (msg) {

            if (msg.success=="0"){
                $("input[name='id']").val(msg.data.id);
            $("input[name='username']").val(msg.data.username);
            $("input[name='nickname']").val(msg.data.nickname);
            $("input[name='phone']").val(msg.data.phone);
                $("input[name='email']").val(msg.data.email);
                $("input[name='birthday']").val(msg.data.birthday);
                $("input[name='sex']").val(msg.data.sex);
                $("input[name='status']").val(msg.data.status);
            }
        })
        //监听提交


        $.get("/select/sex",{id:data.sex},function (msg) {
            if(msg.success=="0"){
                var list=msg.data;
                var options="";
                for (var i in list) {
                    if (list[i].selected){options+="<option selected value='"+list[i].id+"'>"+list[i].text+"</option>";}
                    else {
                    options+="<option value='"+list[i].id+"'>"+list[i].text+"</option>";
                    }
                }
                $("[name='sex']").html(options);
            }
            form.render('select');
        });

        console.log(status);
        $.get("/select/state",{id:data.status},function (msg) {
            if(msg.success=="0"){
                var list=msg.data;
                var options="";
                for (var i in list) {
                    if (list[i].selected){    options+="<option selected value='"+list[i].id+"'>"+list[i].text+"</option>";}
                    else {
                        options+="<option value='"+list[i].id+"'>"+list[i].text+"</option>";
                    }
                }
                $("[name='status']").html(options);
            }

            form.render('select');
        });
        form.on('submit(formDemo)', function(data){
            $.post("/sysusers/sysuser",data.field,function (msg) {
                if (msg.success=='0'){
                    parent.layui.table.reload("user-tab");
                    //获取弹出窗口的id
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);//关闭弹出窗口
                }

            })

            return false;
        });
    });

</script>
</html>